package thread.synchroCode;

public class _01UseSynchronized {
  public static int inventory = 10;
  public static Object room = new Object();

  public static void main(String[] args) {
    new Thread(() -> {
      for (int i = 0; i < 1000000; i++) {
        synchronized (room){
          inventory++;
        }
      }
    }, "t1").start();

    new Thread(() -> {
      for (int i = 0; i < 1000000; i++) {
        synchronized (room){
          inventory--;
        }
      }
    }, "t2").start();

    System.out.println(inventory);
  }
}
